/*
 * @Description:
 * @version:
 * @Author: sunqian_sr
 * @Date: 2022-11-21 09:58:40
 * @LastEditors: Andy
 * @LastEditTime: 2023-02-28 09:58:13
 */
import { Cookies } from '@package/service'
import elementEnLocale from 'element-ui/lib/locale/lang/en' // element-ui lang
import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN' // element-ui lang
import Vue from 'vue'
import VueI18n from 'vue-i18n'

import supplierEn from '@package/components/src/workflow/components/workFlowForm/supplierInformation/i18n/en_US'
import supplierZh from '@package/components/src/workflow/components/workFlowForm/supplierInformation/i18n/zh_CN.js'
import localeEn from './locale/en_US.js'
import localeZh from './locale/zh_CN.js'

Vue.use(VueI18n)

/**
 * 浏览器默认语言
 * @type {string}
 */
const navigatorLang = navigator.language.replace('-', '_')

const defaultLang = Cookies.get('language') || navigatorLang

const messages = {
  en_US: {
    ...localeEn,
    ...supplierEn,
    ...elementEnLocale // 或者用 Object.assign({ message: 'hello' }, enLocale)
  },
  zh_CN: {
    ...localeZh,
    ...supplierZh,
    ...elementZhLocale // 或者用 Object.assign({ message: '你好' }, zhLocale)
  }
}
console.log(messages, 'messages')
const i18n = new VueI18n({
  locale: defaultLang,
  messages,
  silentTranslationWarn: true
})
/**
 * 默认语言
 * @type {*[]}
 */
i18n.languages = [
  { value: 'zh_CN', name: '简体中文' },
  { value: 'en_US', name: 'English' }
]
/**
 * 切换语言
 * @param newLocale
 */
i18n.setLocale = (newLocale) => {
  i18n.locale = newLocale
  Cookies.set('language', newLocale)
}
export default i18n
